﻿using FluentMigrator;
using Smartstore.Core.Identity;
using Smartstore.Core.Stores;
using Smartstore.Core.Catalog.Products;
using Smartstore.Core.Catalog.Discounts;
using Smartstore.Core.Catalog.Attributes;

namespace Smartstore.Core.Data.Migrations
{
    [MigrationVersion("2024-10-09 14:37:00", "Core: ProductChange")]
    internal class ProductChange : Migration
    {
        public override void Up()
        {
            var tableName = nameof(Product);
            var producer = nameof(Product.Producer);
            var limitedToStoreId = nameof(Product.LimitedToStoreId);

            //const string LimitedToStoresColumn = "LimitedToStores";
            //const string LimitedToStoresIndex = "IX_Product_LimitedToStores";

            if (!Schema.Table(tableName).Column(producer).Exists())
            {
                Create.Column(producer).OnTable(tableName).AsString(400).Nullable();
            }

            if (!Schema.Table(tableName).Column(limitedToStoreId).Exists())
            {
                Create.Column(limitedToStoreId).OnTable(tableName).AsInt32().NotNullable().WithDefaultValue(0);
            }

            //if (Schema.Table(tableName).Index(LimitedToStoresIndex).Exists())
            //{
            //    Delete.Index(LimitedToStoresIndex).OnTable(producer);
            //}

            //if (Schema.Table(tableName).Column(LimitedToStoresColumn).Exists())
            //{
            //    Delete.Column(LimitedToStoresColumn).FromTable(producer);
            //}

        }

        public override void Down()
        {
        }
    }
}
